// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "Engine/DeveloperSettings.h"
#include "GameplayTagContainer.h"
#include "Subsystems/WorldSubsystem.h"

#include "LyraContextEffectsSubsystem.generated.h"

#define UE_API LYRAGAME_API

enum EPhysicalSurface : int;

class AActor;
class UAudioComponent;
class ULyraContextEffectsLibrary;
class UNiagaraComponent;
class USceneComponent;
struct FFrame;
struct FGameplayTag;
struct FGameplayTagContainer;

/**
 * Lyra上下文效果设置类
 */
UCLASS(MinimalAPI, config = Game, defaultconfig, meta = (DisplayName = "LyraContextEffects"))
class ULyraContextEffectsSettings : public UDeveloperSettings
{
	GENERATED_BODY()

public:
	// 表面类型到上下文映射
	UPROPERTY(config, EditAnywhere)
	TMap<TEnumAsByte<EPhysicalSurface>, FGameplayTag> SurfaceTypeToContextMap; // 表面类型到上下文映射
};

/**
 * Lyra上下文效果集合类
 */
UCLASS(MinimalAPI)
class ULyraContextEffectsSet : public UObject
{
	GENERATED_BODY()

public:
	UPROPERTY(Transient)
	TSet<TObjectPtr<ULyraContextEffectsLibrary>> LyraContextEffectsLibraries; // Lyra上下文效果库集合
};


/**
 * Lyra上下文效果子系统类
 */
UCLASS(MinimalAPI)
class ULyraContextEffectsSubsystem : public UWorldSubsystem
{
	GENERATED_BODY()
	
public:
	/**
	 * 生成上下文效果
	 */
	UFUNCTION(BlueprintCallable, Category = "ContextEffects")
	UE_API void SpawnContextEffects(
		const AActor* SpawningActor // 生成Actor
		, USceneComponent* AttachToComponent // 附加到的组件
		, const FName AttachPoint // 附加点
		, const FVector LocationOffset // 位置偏移
		, const FRotator RotationOffset // 旋转偏移
		, FGameplayTag Effect // 效果标签
		, FGameplayTagContainer Contexts // 上下文容器
		, TArray<UAudioComponent*>& AudioOut // 音频输出数组
		, TArray<UNiagaraComponent*>& NiagaraOut // Niagara输出数组
		, FVector VFXScale = FVector(1) // VFX缩放，默认为(1,1,1)
		, float AudioVolume = 1 // 音频音量，默认为1
		, float AudioPitch = 1); // 音频音高，默认为1

	/**
	 * 从表面类型获取上下文
	 */
	UFUNCTION(BlueprintCallable, Category = "ContextEffects")
	UE_API bool GetContextFromSurfaceType(TEnumAsByte<EPhysicalSurface> PhysicalSurface, FGameplayTag& Context);

	/**
	 * 加载并添加上下文效果库
	 */
	UFUNCTION(BlueprintCallable, Category = "ContextEffects")
	UE_API void LoadAndAddContextEffectsLibraries(AActor* OwningActor, TSet<TSoftObjectPtr<ULyraContextEffectsLibrary>> ContextEffectsLibraries);

	/**
	 * 卸载并移除上下文效果库
	 */
	UFUNCTION(BlueprintCallable, Category = "ContextEffects")
	UE_API void UnloadAndRemoveContextEffectsLibraries(AActor* OwningActor);

private:

	UPROPERTY(Transient)
	TMap<TObjectPtr<AActor>, TObjectPtr<ULyraContextEffectsSet>> ActiveActorEffectsMap; // 活动Actor效果映射

};

#undef UE_API